import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)
//types
const types = {
  SET_LOCALTION: "SET_LOCALTION",
  SET_ADDRESS: 'SET_ADDRESS',
  SET_WEATHER: 'SET_WEATHER',
  SET_LAT: "SET_LAT",
  SET_LNG: "SET_LNG",
  ORDER_INFO: "ORDER_INFO",
  USER_INFO: "USER_INFO",
  TOTAL_PRICE: "TOTAL_PRICE",
  REMARK_INFO: "REMARK_INFO"
}
//state
const state = {
  localtion: {},
  address: '',
  weather: {},
  lat: '',
  lng: '',
  orderInfo: null,
  userInfo: null,
  totalPrice: 0,
  remarkInfo: {
    tableware: '',
    remark: ''
  },

}
//getters
const getters = {
  localtion: state => state.localtion,
  address: state => state.address,
  weather: state => state.weather,
  lat: state => state.lat,
  lng: state => state.lng,
  orderInfo: state => state.orderInfo,
  userInfo: state => state.userInfo,
  totalPrice: state => state.totalPrice,
  remarkInfo: state => state.remarkInfo,
}
//mutations
const mutations = {
  [types.SET_LOCALTION](state, localtion) {
    if (localtion) {
      state.localtion = localtion;
    } else {
      state.localtion = null
    }
  },
  [types.SET_ADDRESS](state, address) {
    if (address) {
      state.address = address;
    } else {
      state.address = null
    }
  }, [types.SET_WEATHER](state, weather) {
    if (weather) {
      state.weather = weather;
    } else {
      state.weather = null
    }
  },
  [types.SET_LAT](state, lat) {
    if (lat) {
      state.lat = lat;
    } else {
      state.lat = null
    }
  },
  [types.SET_LNG](state, lng) {
    if (lng) {
      state.lng = lng;
    } else {
      state.lng = null
    }
  },
  [types.ORDER_INFO](state, orderInfo) {
    if (orderInfo) {
      state.orderInfo = orderInfo;
    } else {
      state.orderInfo = null
    }
  },
  [types.USER_INFO](state, userInfo) {
    if (userInfo) {
      state.userInfo = userInfo;
    } else {
      state.userInfo = null
    }
  },
  [types.TOTAL_PRICE](state, totalPrice) {
    if (totalPrice) {
      state.totalPrice = totalPrice;
    } else {
      state.totalPrice = null
    }
  },
  [types.REMARK_INFO](state, remarkInfo) {
    if (remarkInfo) {
      state.remarkInfo = remarkInfo;
    } else {
      state.remarkInfo = null
    }
  },
}
//actions
const actions = {
  setLocaltion: ({ commit }, localtion) => {
    commit(types.SET_LOCALTION, localtion)
  },
  setAddress: ({ commit }, address) => {
    commit(types.SET_ADDRESS, address)
  },
  setWeather: ({ commit }, weather) => {
    commit(types.SET_WEATHER, weather)
  },
  setLat: ({ commit }, lat) => {
    commit(types.SET_LAT, lat)
  },
  setLng: ({ commit }, lng) => {
    commit(types.SET_LNG, lng)
  },
  setOrderInfo: ({ commit }, orderInfo) => {
    commit(types.ORDER_INFO, orderInfo)
  },
  setUserInfo: ({ commit }, userInfo) => {
    commit(types.USER_INFO, userInfo)
  },
  setTotalPrice: ({ commit }, totalPrice) => {
    commit(types.TOTAL_PRICE, totalPrice)
  },
  setRemarkInfo: ({ commit }, remarkInfo) => {
    commit(types.REMARK_INFO, remarkInfo)
  },
}

export default new Vuex.Store({
  state,
  getters,
  mutations,
  actions,
})